﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class QTDAOPHAPDAO:IData<QTDAOPHAP> 
 	{
		public QTDAOPHAPDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref QTDAOPHAP item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + QTDAOPHAP.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_QTDAOPHAP", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + QTDAOPHAP.c_TGDP, item.TGDP),
				 new SqlParameter("@" + QTDAOPHAP.c_NVID, item.NVID), 
                 new SqlParameter("@" + QTDAOPHAP.c_DPID, item.DPID));
			if(t == 0){
                item.ID = Convert.ToInt32(obj);
            }
			return i;
		}

		public override QTDAOPHAP GetItem(IDataReader dr)
		{
			QTDAOPHAP obj = new QTDAOPHAP();
			obj.ID = Convert.ToInt32(dr[QTDAOPHAP.c_ID]);			
			obj.TGDP = Convert.ToString(dr[QTDAOPHAP.c_TGDP]);
			obj.NVID = Convert.ToInt32(dr[QTDAOPHAP.c_NVID]);
			obj.DPID = Convert.ToInt32(dr[QTDAOPHAP.c_DPID]);
            obj.TENDP = Convert.ToString(dr[QTDAOPHAP.c_TENDP]);
            obj.TENNV = Convert.ToString(dr[QTDAOPHAP.c_TENNV]);
			return obj;
		}

		public override List<QTDAOPHAP> GetAll()
		{
			return GetAll("sp_GetAllQTDAOPHAP", CommandType.StoredProcedure);
		}

		public override QTDAOPHAP GetItemById(object id)
		{
			return GetAll().SingleOrDefault();
		}
		public override QTDAOPHAP GetItemById(QTDAOPHAP item){
			throw new NotImplementedException();
		}

	}

 }
